/*
 * @Description:
 * @Author: Zzt
 * @Date: 2022-08-27 11:31:22
 * @LastEditTime: 2023-03-02 17:31:32
 */
import { createContext, useReducer, useEffect, useContext } from 'react';
import {
  SET_CONDITION,
  SET_SELECT_AT,
  SET_SELECT_FOND_ID,
  SET_SELECT_AT_ID,
  SET_FIELDCONDITION
} from '../constants';
import { ImageSearchReducer } from '../reducers/ImageSearchReducer';

const initialState = { conditions: [], fieldConditionList: {} };

const ImageSearchContext = createContext();

const ImageSearchContextProvider = (props) => {
  const [state, dispatch] = useReducer(ImageSearchReducer, initialState);

  const actions = {
    getCondition(data) {
      console.log('context', data);
      dispatch({ type: SET_CONDITION, data });
    },
    getFieldConditionList(data) {
      dispatch({ type: SET_FIELDCONDITION, data });
    },
    /**
     * @description: 设置选中的档案类型
     */
    setSelectAT(data) {
      dispatch({ type: SET_SELECT_AT, data });
    },

    /**
     * @description: 设置选中的全宗
     */
    setSelectFondId(id) {
      dispatch({ type: SET_SELECT_FOND_ID, id });
    },

    /**
     * @description: 设置选中的档案类型ID
     */
    setSelectATId(id) {
      dispatch({ type: SET_SELECT_AT_ID, id });
    }
  };
  useEffect(() => {}, []);
  return (
    <ImageSearchContext.Provider value={{ ...state, ...actions }}>
      {props.children}
    </ImageSearchContext.Provider>
  );
};
export const useImageSearchContext = () => {
  return useContext(ImageSearchContext);
};
export { ImageSearchContext, ImageSearchContextProvider };
